package basic.java.bitcal;

import java.util.Arrays;
import java.util.Random;

/**
 * @创建人 MBY381
 * @创建时间 2022/3/30 14:31
 * @描述 暂无
 */
public class NXOR_inclusive_OR {
    public static int findcf(int n) {

        int[] nums = new int[n + 1];
        for (int i = 0; i < n; i++) {
            nums[i] = i + 1;
        }
        nums[n] = new Random().nextInt(n) + 1;
        int temp = nums[n];
        System.out.println("重复元素为：" + temp);

        int temp2 = new Random().nextInt(n);
        System.out.println("交换位置" + temp2);
        nums[n] = nums[temp2];
        nums[temp2] = temp;
        System.out.println(Arrays.toString(nums));
        int ans = nums[0];
        for (int i = 1; i < nums.length; i++) {
            ans = ~(nums[i] ^ ans);
        }
//        for(int i=0;i<nums.length;i++){
//            ans=nums[i]^ans;
//        }
        return ans;
    }

    /**
     * 充分证明了同或采用  ~（a^b）   是不可行的
     *
     * @param args
     */
    public static void main(String[] args) {
        int a = 3, b = 2;
        int c = ~(a ^ b);
        System.out.println(Integer.toBinaryString(a));
        System.out.println(Integer.toBinaryString(b));
        System.out.println(Integer.toBinaryString(c));
        System.out.println(c);
        System.out.println(Integer.toString(1000, 16));

        System.out.println(findcf(100));
    }
}
